package com.example.rocketmq_demo.producer;

import com.example.rocketmq_demo.entity.RocketMqMsgDto;
import com.example.rocketmq_demo.impl.RocketMqService;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author xyh
 * 2021/8/26
 */
public class delayedProducer {



    public static void main(String[] args) throws Exception {


        RocketMqService rocketMqService;
        DefaultMQProducer producer = new DefaultMQProducer("one");
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.setSendMsgTimeout(60000);
        producer.start();
        RocketMqMsgDto rocketMqMsgDto = new RocketMqMsgDto();
        rocketMqMsgDto.setContent("你好吗o(╥﹏╥)o");
        rocketMqMsgDto.setTopic("topic4");
        rocketMqMsgDto.setTags("top4");
        RocketMqService rocketMqService1 = new RocketMqService() {
            @Override
            public void send(RocketMqMsgDto dto) {

            }

            @Override
            public void asyncSend(RocketMqMsgDto dto) {

            }

            @Override
            public void syncSendOrderly(RocketMqMsgDto dto) {

            }
        };
        for (int i = 0; i < 1; i++) {
            byte[] body = ("这是一个日程对象sssss," + i).getBytes();
            Message msg = new Message("TopicOne", "oneTag", body);
            //msg.getBytes("UTF-8");
            // 指定消息延迟等级为3级，即延迟10s //
            msg.setDelayTimeLevel(1);
            SendResult sendResult = producer.send(msg);
            // 输出消息被发送的时间
            System.out.print(new SimpleDateFormat("mm:ss").format(new Date()));
            System.out.println(" ," + sendResult);
        }
        producer.shutdown();
    }
}
